//
//  WCNOrderDetailFooterView.m
//  OrderDetailVC
//
//  Created by wsj2015 on 15/11/3.
//  Copyright © 2015年 wsj2015. All rights reserved.
//
#import <UIKit/UIKit.h>

#define payMethodLabelW 100
#define payMethodLabelH 25
#define payBtnW payMethodLabelH
@interface PayMentodBtn : UIView
{
    UIButton *_btn;
    UILabel  *_label;
    NSInteger _sIndex;
   
    
}
@property (nonatomic ,copy)void(^payMethodBlock)(NSInteger );
@end

@implementation PayMentodBtn

- (instancetype)initWithFrame:(CGRect)frame
{
    if (self =[super initWithFrame:frame]) {
        
        NSArray *titleArry =@[@"在线支付",@"线下支付"];
        CGFloat Y = 0;
        CGFloat edgeSapce =45;
        CGFloat space = self.frame.size.width -2 *edgeSapce  - 2*123 + 30;
        for (int i = 0 ; i<2; i++) {
            
            UIButton *btn =[UIButton buttonWithType:UIButtonTypeCustom];
            btn.layer.cornerRadius = 11;
            btn.layer.masksToBounds =YES;
//            btn.layer.borderWidth = 2;
//            btn.layer.borderColor =[UIColor redColor].CGColor;
            [btn setBackgroundImage:[UIImage imageNamed:@"payMethod-1"] forState:UIControlStateSelected];
            [btn setBackgroundImage:[UIImage imageNamed:@"payMethod-2"] forState:UIControlStateNormal];
            [btn addTarget:self action:@selector(payMethodAction:) forControlEvents:UIControlEventTouchUpInside];
            [btn setBackgroundColor:[UIColor whiteColor]];
            btn.tag = 100 +i;
            UILabel  *label =[[UILabel alloc]init];
            label.text = titleArry[i];
            label.font = [UIFont systemFontOfSize: 16];
            btn.frame = CGRectMake(edgeSapce +(payBtnW + payMethodLabelW + space)*i, Y, payBtnW, payBtnW);
            label.frame =CGRectMake(CGRectGetMaxX(btn.frame), Y, payMethodLabelW, payMethodLabelH);
            [self addSubview:btn];
            [self addSubview:label];
            if (i == 0) {
                _sIndex = 0;
                btn.selected = YES;
//                btn.backgroundColor =[UIColor greenColor];
            }
        }
        
    }
  
    return self;
}
- (void)payMethodAction:(UIButton *)btn
{
    
    UIButton *preBtn =[self viewWithTag:_sIndex + 100];
   
   
    if (preBtn == btn) {
        return;
    }
     preBtn.selected = NO;
//     preBtn.backgroundColor = [UIColor whiteColor];
//    btn.backgroundColor =[UIColor greenColor];
    btn.selected = YES;
    _sIndex  = btn.tag  -100;
    if (self.payMethodBlock) {
        self.payMethodBlock(btn.tag -100);
    }
   
 
}


@end
#import "WCNOrderDetailFooterView.h"
#import "WCInfoEditView.h"
#import "Macros.h"
@implementation WCNOrderDetailFooterView
{
    UIButton *_feeBtn;
    float _price;
}


- (instancetype)initWithFrame:(CGRect)frame
{
    if (self =[super initWithFrame:frame]) {
//        self.backgroundColor  =[ UIColor orangeColor];
        CGFloat maxY = 0;
        
        self.layer.cornerRadius = 1;
//        self.layer.borderColor = [UIColor grayColor].CGColor;
//        self.layer.borderWidth = 1;
        UIView *bgView =[[UIView alloc] initWithFrame:CGRectMake(0, 0, self.frame.size.width, self.frame.size.height)];
        [self addSubview:bgView];
        
        PayMentodBtn *payMethodView =[[PayMentodBtn alloc] initWithFrame:CGRectMake(0, 30, self.frame.size.width, 30)];
//        payMethodView.backgroundColor = [UIColor  purpleColor];
        payMethodView.payMethodBlock = ^(NSInteger number){
            if (self.choosePayMethod) {
                if (number == 0) {
                    self.choosePayMethod(YES);
                }else{
                    self.choosePayMethod(NO);
                }
            }
          
        };
        [bgView addSubview:payMethodView];
        
        maxY = CGRectGetMaxY(payMethodView.frame);
        
        UIView *payFeeView = [[UIView alloc] initWithFrame:CGRectMake(0, maxY, self.frame.size.width, 30)];
//        payFeeView.backgroundColor =[UIColor yellowColor];
        [bgView addSubview:payFeeView];
        
        UILabel *freeTitleLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, 1, 130, 28)];
        freeTitleLabel.text  =@"实际支付金额:";
        freeTitleLabel.textAlignment = NSTextAlignmentCenter;
        freeTitleLabel.font  =[UIFont systemFontOfSize:16];
        [payFeeView addSubview:freeTitleLabel];
       
        _feeBtn  =[ UIButton buttonWithType:UIButtonTypeCustom];
        CGFloat feeBtnX = CGRectGetMaxX(freeTitleLabel.frame) +5;
        _feeBtn.frame = CGRectMake(feeBtnX ,1, self.frame.size.width -feeBtnX -20, 28);
        _feeBtn.backgroundColor = [UIColor whiteColor];
        _feeBtn.layer.borderColor = [UIColor blackColor].CGColor;
        [_feeBtn setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
        _feeBtn.titleLabel.textAlignment = NSTextAlignmentRight;
        _feeBtn.layer.borderWidth = 1;
        _feeBtn.titleLabel.textAlignment = NSTextAlignmentRight;
        [_feeBtn addTarget:self action:@selector(editFeeAction:) forControlEvents:UIControlEventTouchUpInside];
        [payFeeView addSubview:_feeBtn];
       
        maxY = CGRectGetMaxY(payFeeView.frame);
        
        NSArray *confirTitileArr =@[@"确认订单",@"取消订单"];
        CGFloat confirmBtnW = 100;
        CGFloat confirmBtnH = 30;
        CGFloat edgeS =(kScreenWidth - 60 -confirmBtnW *2)/2;
        CGFloat confirmBtnY = 30 +maxY;
        for (int i  = 0; i< 2; i++) {
            UIButton *btn =[UIButton buttonWithType:UIButtonTypeCustom];
            btn.frame =CGRectMake(edgeS + (confirmBtnW +60)*i, confirmBtnY, confirmBtnW, confirmBtnH);
            btn.backgroundColor  = HexRGB_WSJ(22, 155, 244);
          
            [btn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
            [btn setTitle:confirTitileArr[i] forState:UIControlStateNormal];
            btn.tag = 300 + i;
            btn.layer.cornerRadius =10;
            btn.layer.masksToBounds =YES;
            [btn addTarget:self action:@selector(comfirmAction:) forControlEvents:UIControlEventTouchUpInside];
            btn.titleLabel.font  =[UIFont systemFontOfSize:20];
            [self addSubview:btn];
        }
//
        
        
    }
    return self;
 
}
- (void)comfirmAction:(UIButton *)btn
{
    if (self.confimOrderBlock) {
        if (btn.tag - 300 ==0) {
             self.confimOrderBlock(YES);
        }else{
              self.confimOrderBlock(NO);
        }
       
    }
}
- (void)editFeeAction:(UIButton *)btn
{
    WCInfoEditView *editView = [[WCInfoEditView alloc] init];
    editView.type = WCInfoEditTypeMoney;
    editView.titleLabel.text = @"编辑价格";
    editView.textField.keyboardType = UIKeyboardTypeDecimalPad;
    weakSelf_define;
    editView.save = ^(NSString *txt){
        NSString *new =[NSString stringWithFormat:@"￥%@元",txt];
        CGFloat price = [txt floatValue];
        if (weakSelf.priceChangedBlock) {
            weakSelf.priceChangedBlock(price);
        }
        [btn setTitle:new forState:UIControlStateNormal];
              return YES;
    };
    //在哪里 显示
    if (self.showEditorBlock) {
        UIView *view = self.showEditorBlock();
        [editView showIn:view animated:YES];
    }
    
 
}
@end



